#include "QQTextEditPrivate.h"

#include <ElaApplication.h>

#include "QQTextEdit.h"

QQTextEditPrivate::QQTextEditPrivate(QObject* parent)
	: QObject{ parent }
{
}

QQTextEditPrivate::~QQTextEditPrivate()
{
}

void QQTextEditPrivate::onWMWindowClickedEvent(const QVariantMap& data)
{
	Q_Q(QQTextEdit);
	ElaAppBarType::WMMouseActionType actionType = data.value("WMClickType").value<ElaAppBarType::WMMouseActionType>();
	if (actionType == ElaAppBarType::WMLBUTTONDOWN)
	{
		if (!q->toPlainText().isEmpty() && q->hasFocus())
		{
			q->clearFocus();
		}
	}
	else if (actionType == ElaAppBarType::WMLBUTTONUP || actionType == ElaAppBarType::WMNCLBUTTONDOWN)
	{
		if (ElaApplication::containsCursorToItem(q) || (actionType == ElaAppBarType::WMLBUTTONUP && !q->toPlainText().isEmpty()))
		{
			return;
		}
		if (q->hasFocus())
		{
			q->clearFocus();
		}
	}
}

void QQTextEditPrivate::onThemeChanged(ElaThemeType::ThemeMode themeMode)
{
	Q_Q(QQTextEdit);
	if (themeMode == ElaThemeType::Light)
	{
		QPalette palette;
		palette.setColor(QPalette::Text, Qt::black);
		palette.setColor(QPalette::PlaceholderText, QColor(0x00, 0x00, 0x00, 128));
		q->setPalette(palette);
	}
	else
	{
		QPalette palette;
		palette.setColor(QPalette::Text, Qt::white);
		palette.setColor(QPalette::PlaceholderText, QColor(0xBA, 0xBA, 0xBA));
		q->setPalette(palette);
	}
}
